package com.tanhua.server.controller;


import com.sun.org.apache.regexp.internal.RE;
import com.tanhua.server.service.TodayBestService;
import com.tanhua.server.utils.Cache;
import com.tanhua.server.vo.PageResult;
import com.tanhua.server.vo.RecommendUserQueryParam;
import com.tanhua.server.vo.TodayBest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;


import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/tanhua")
@Slf4j
public class TodayBestController {
    @Autowired
    private TodayBestService todayBestService;

    /***
     * 今日最佳佳人
     * @param token
     * @return
     */
    @GetMapping("/todayBest")
    public ResponseEntity<TodayBest>queryTodayBest(@RequestHeader("Authorization")String token){
        try {
            TodayBest todayBest=this.todayBestService.queryTodayBest(token);
            if (null!=todayBest){
                return ResponseEntity.ok(todayBest);
            }
        } catch (Exception e) {
            log.error("查询今日佳人出错~token",token,e );
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);

    }

    /**
     * 今日推荐
     * @param token
     * @param queryParam
     * @return
     */
     @GetMapping("/recommendation")
     @Cache(time = "30")
    public ResponseEntity<PageResult>queryRecommendation(@RequestHeader("Authorization")String token, RecommendUserQueryParam queryParam){
         try {
             PageResult pageRequest=this.todayBestService.queryRecommendation(token, queryParam);
             if (null != pageRequest){
                 return ResponseEntity.ok(pageRequest);
             }
         } catch (Exception e) {
             log.error("查询今日推荐失败~token",e );
         }
         return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
     }


}
